<?php

/**
	Theme Ajax Library

	The contents of this file are subject to the terms of the GNU General
	Public License Version 2.0. You may not use this file except in
	compliance with the license. Any of the license terms and conditions
	can be waived if you get permission from the copyright holder.

	Copyright (c) 2011 Bandit Media
	Jermaine Marée

		@package BanditAjax
		@version 1.1
**/

//! BanditAjax
class BanditAjax extends FeatherTheme {

	/**
		Ajax init
			@public
	**/
	static function init() {
		// Add AJAX actions
		add_action('wp_ajax_creatic_ajaxnav',__CLASS__.'::blog_ajaxnav');
		add_action('wp_ajax_nopriv_creatic_ajaxnav',__CLASS__.'::blog_ajaxnav');
		add_action('wp_ajax_creatic_ajaxarchive',__CLASS__.'::archive_ajax');
		add_action('wp_ajax_nopriv_creatic_ajaxarchive',__CLASS__.'::archive_ajax');
	}

	/**
		Blog Ajax Nav
			@public
	**/
	static function blog_ajaxnav() {
		// Get nonce
		$nonce = esc_attr($_POST['nonce']);
		if(!wp_verify_nonce($nonce,'wpb-creatic-ajax-nonce'))
			die('error');
		// Get args
		$args = $_POST['args'];
		// Set query args
		$offset = esc_attr($args['offset']);
		$catid = isset($args['catid'])?esc_attr($args['catid']):'';
		$tagid = isset($args['tagid'])?esc_attr($args['tagid']):'';
		$authorid = isset($args['authorid'])?esc_attr($args['authorid']):'';
		$search = isset($args['search'])?esc_attr($args['search']):'';
		// Query posts
		query_posts(
			array(
				'post_status'	=> 'publish',
				'offset'		=> $offset,
				'cat'			=> $catid,
				'tag'			=> $tagid,
				'author'		=> $authorid,
				's'				=> $search
			)
		);
		require(get_template_directory().'/feather/tmpl/ajax-posts.php');
		die();
	}

	/**
		Archive Ajax
			@public
	**/
	static function archive_ajax() {
		$nonce = esc_attr($_POST['nonce']);
		if(!wp_verify_nonce($nonce,'wpb-creatic-ajax-nonce'))
			die('error');
		// Get template
		require(get_template_directory().'/feather/tmpl/ajax-archive.php');
		die();
	}

}